import {observable, action} from "mobx";
import request from "../utils/request";
import * as api from "../api/api";
import {LoadHoc, loading} from '../hoc/loadHoc';

export default class PublicWelfareStore extends LoadHoc {
  /**
   * 首页banner
   */
  @observable banners: api.YNJWTPointMallVOBannerVO = {};

  @loading @action
  async getBanners(params: {
    callback?: (banners: api.YNJWTPointMallVOBannerVO) => void;
  }) {
    const {callback} = params;
    const banners = await request(api.ApppublicWelfareApiFetchParamCreactor.apppublicWelfareGetBannersAsync({}));
    this.banners = banners;
    callback && callback(banners);
  }

  /**
   * 首页慈善总数据
   */

  @loading @action
  async getAllPublicWelfareMoney(params: {
    callback?: (res: api.YNJWTPublicWelfareVOPublicWelfareMoneyVO) => void;
  }) {
    const {callback} = params;
    const allPublicWelfareMoney = await request(api.ApppublicWelfareApiFetchParamCreactor.apppublicWelfareGetAllPublicWelfareMoneyAsync({}));
    callback && callback(allPublicWelfareMoney);
  }

  /**
   * 首页公益和活动信息
   */
  @observable publicWelfare: api.YNJWTPublicWelfareVOPublicWelfareVO = {};

  @loading @action
  async getPublicWelfare(params: {
    callback?: (res: api.YNJWTPublicWelfareVOPublicWelfareVO) => void;
  }) {
    const {callback} = params;
    const publicWelfare = await request(api.ApppublicWelfareApiFetchParamCreactor.apppublicWelfareGetPublicWelfareAsync({}));
    this.publicWelfare = publicWelfare;
    callback && callback(publicWelfare);
  }

  /**
   * 首页公益详情
   */
  @observable publicWelfareInfo: api.YNJWTPublicWelfareVOWelfareVO = {};

  @loading @action
  async getPublicWelfareInfo(params: {
    formId: number,
    callback?: (res: api.YNJWTPublicWelfareVOWelfareVO) => void;
  }) {
    const {formId, callback} = params;
    const publicWelfareInfo = await request(api.ApppublicWelfareApiFetchParamCreactor.apppublicWelfareGetPublicWelfareInfoAsync({
      formId
    }));
    this.publicWelfareInfo = publicWelfareInfo;
    callback && callback(publicWelfareInfo);
  }

  /**
   * 首页活动详情
   */
  @observable activitiesInfo: api.YNJWTPublicWelfareVOWelfareVO = {};

  @loading @action
  async getActivitiesInfo(params: {
    formId: number,
    callback?: (res: api.YNJWTPublicWelfareVOWelfareVO) => void;
  }) {
    const {formId, callback} = params;
    const activitiesInfo = await request(api.ApppublicWelfareApiFetchParamCreactor.apppublicWelfareGetActivitiesInfoAsync({
      formId
    }));
    this.activitiesInfo = activitiesInfo;
    callback && callback(activitiesInfo);
  }

  /**
   * 公益列表
   */
  @observable pagedPublicWelfare: api.YNJWTPublicWelfareVOWelfareVO = {};

  @loading @action
  async getPagedPublicWelfare(params: {
    pageIndex: number,
    pageSize: number,
    callback?: (res: api.YNJWTPublicWelfareVOWelfareVO) => void;
  }) {
    const {pageIndex, pageSize, callback} = params;
    const pagedPublicWelfare = await request(api.ApppublicWelfareApiFetchParamCreactor.apppublicWelfareGetPagedPublicWelfareAsync({
      formSkipCount: (pageIndex - 1) * pageSize,
      formMaxResultCount: pageSize
    }));
    this.pagedPublicWelfare = pagedPublicWelfare;
    callback && callback(pagedPublicWelfare);
  }

  /**
   * 活动列表
   */
  @observable pagedActivitiesInfo: api.YNJWTPublicWelfareVOWelfareVO = {};

  @loading @action
  async getPagedActivitiesInfo(params: {
    pageIndex: number,
    pageSize: number,
    callback?: (res: api.YNJWTPublicWelfareVOWelfareVO) => void;
  }) {
    const {pageIndex, pageSize, callback} = params;
    const pagedActivitiesInfo = await request(api.ApppublicWelfareApiFetchParamCreactor.apppublicWelfareGetPagedActivitiesInfoAsync({
      formSkipCount: (pageIndex - 1) * pageSize,
      formMaxResultCount: pageSize
    }));
    this.pagedActivitiesInfo = pagedActivitiesInfo;
    callback && callback(pagedActivitiesInfo);
  }

  /**
   * 资助申请保存
   */
  @loading @action
  async savePublicWelfare(params: {
    form: {
      name: string,
      phoneNumber: string,
      logoImg: string,
      publicWelfaresBanner: string,
      introduce: string,
      description: string,
      amountOfApplication: number,
    },
    callback?: (res) => void;
  }) {
    const {form, callback} = params;
    const res = await request(api.ApppublicWelfareApiFetchParamCreactor.apppublicWelfareSavePublicWelfareAsync({
      form
    }));
    callback && callback(res);
  }

  /**
   * 资助付款按钮
   */
  @loading @action
  async publicWelfareBuy(params: {
    form: {
      publicWelfareId: number,
      payMoney: number
    },
    callback?: (res) => void;
  }) {
    const {form, callback} = params;
    const res = await request(api.ApppublicWelfareApiFetchParamCreactor.apppublicWelfarePublicWelfareBuyAsync({
      form
    }));
    callback && callback(res);
  }
}
